home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / ust1a.arc / DOST2B.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-09-05  |  2.9 KB  |  146 lines

  1. /*+
  2.  * File: dost2b.c
  3.  * Description:
  4.  *  dost2b is a filter.
  5.  *  dost2b processes i_files or the standard input.
  6.  *  dost2b writes to o_file or standard output.
  7.  *
  8.  *  Converts a DOS text file to binary file.
  9.  *  Replaces <cr><lf> to <lf>.
  10.  *
  11.  * Usages:
  12.  *  dost2b [-o] <o_file> <i_files>
  13.  * 
  14.  *
  15.  *  Author: Mohsen Banan.
  16.  *
  17.  *  This program is public domain software, no warranty intended or
  18.  *  implied.
  19.  *  General permission to copy or modify, but not for profit,  is
  20.  *  hereby  granted.
  21.  *
  22.  *
  23.  * Functions:
  24.  *
  25.  *
  26.  * Audit Trail:  $Log:    dost2b.c,v $
  27.  * Revision 1.1  85/08/28  08:38:28  mohsen
  28.  * original posting to the net
  29.  * 
  30.  * 
  31.  *
  32. -*/
  33.  
  34. #ifdef RCS_VER
  35. static char *rcs = "$Header: dost2b.c,v 1.1 85/08/28 08:38:28 mohsen Exp $";
  36. #endif
  37.  
  38. /* #includes */
  39. #include "mbstd.h"
  40. #include <stdio.h>
  41. #include <ctype.h>
  42. #include <fcntl.h>
  43. #ifdef unix
  44. #include "msc3.h"
  45. #endif
  46.  
  47. /* #defines */
  48.  
  49. /* external variables */
  50.  
  51. /* referenced external function declarations */
  52.  
  53. /* internal function declarations */
  54. PUBLIC VOID dost2b();
  55. PUBLIC VOID cant_open();
  56. STATIC VOID usage();
  57.  
  58. /* global variables */
  59.  
  60. /* static variables */
  61. STATIC CHAR * prog_name;
  62.  
  63. INT
  64. main (argc, argv)
  65. INT argc;
  66. CHAR * argv[];
  67. {
  68.     dost2b(argc, argv);
  69. }
  70.     
  71.  
  72. /*<
  73.  * Function:dost2b
  74.  * Description:
  75.  *
  76.  * Returns:
  77.  *  VOID
  78.  * 
  79. >*/
  80. PUBLIC VOID 
  81. dost2b (argc,argv)
  82. INT argc;
  83. CHAR * argv[];
  84. {
  85.     FILE * i_fp;
  86.     FILE * o_fp;
  87.  
  88.     INT i;
  89.     INT c;
  90.  
  91.     i_fp = stdin;
  92.     o_fp = stdout;
  93.     prog_name = argv[0];
  94.     for (i=1; i<argc; ++i) {
  95.         if (*argv[i] == '-') {
  96.             /* To handle concatenated switches */
  97.             INT j;
  98.             j=i;
  99.             while (*(++argv[j])) {
  100.                 switch (*argv[j]) {
  101.                 case 'o':
  102.                 case 'O':
  103.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  104.                         cant_open (prog_name, argv[i]);
  105.                         exit (1);
  106.                     }
  107.                     break;
  108.                 default:
  109.                     usage();
  110.                     exit(1);
  111.                 } /* switch (*argv[j]) */
  112.             } /* while (*(++argv[j])) */
  113.         } /* if '-' */
  114.         else {
  115.             if (!(i_fp = fopen (argv[i], "r"))) {
  116.                 cant_open (prog_name, argv[i]);
  117.                 exit (1);
  118.             } 
  119.             setmode (fileno(i_fp), O_TEXT);
  120.             setmode (fileno(o_fp), O_BINARY);
  121.             while (( c = getc (i_fp)) != EOF) {
  122.                 putc (c, o_fp);
  123.             }
  124.             fclose (i_fp);
  125.         }
  126.     } /* for i<argc */
  127.     fclose (o_fp);
  128.     exit (0);
  129. }
  130.  
  131. PUBLIC VOID
  132. cant_open (prog_name,filename)
  133. CHAR * prog_name;
  134. CHAR * filename;
  135. {
  136.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  137.  
  138. STATIC VOID
  139. usage ()
  140. {
  141.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
  142. }
  143.  
  144.  
  145.